package com.org.javabody.Matches;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MatchIsTrue implements MatchInterface{

	@Override
	public boolean isMatchDate(String date) {
		boolean flag = false;
		if(date.indexOf("-")!=-1) {
			
		}else {
			// /d代表单个数字位(digst)，{4}代表4个连续重复符，/d{4}等价于[0-9]{4}
			// /s代表空格(space)或者tab键
			flag= date.matches("[0-9]{4}[0-1]{1}[0-2]{1}[0-3]{1}[0-9]{1}");
		}
		return flag;
	}
       /**
		 * 判断日期格式和范围
		 */	
	@Override
	public boolean isDate(String date, String format) {
			
		Format f = new SimpleDateFormat(format);
		String tmp = "";
		try {
			Date d = (Date) f.parseObject(date);
			tmp = f.format(d);
		} catch (ParseException e) {
			
		}
		if(tmp.equals(date)){
			return true;
		} else {
			return false;
		}         
	}
	
	public static void main(String[] args) {
		MatchInterface ma = new MatchIsTrue();
		String date = "20171201";
		boolean bo = ma.isMatchDate(date);
		System.out.println(bo);
		
		bo = ma.isDate(date,"yyyyMMdd");
		System.out.println(bo);
	}




}
